package com.hqyj.controller;


import com.hqyj.pojo.TbLetter;
import com.hqyj.pojo.TbLetterEmail;
import com.hqyj.service.TbLetterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.HashMap;

/**
 * <p>
 * 信件表 前端控制器
 * </p>
 *
 * @author gp
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/tb-letter")
public class TbLetterController {
    @Autowired
    TbLetterService tbLetterService;


    /**
     * 新增
     * http://localhost:8080/tb-letter/add
     * {"communityId":"1","communityName":"海棠苑","ownerId":"1","ownerName":"张三","origin":"0",
     * "title":"welcome","content":"xxxxxxxx","createTime":"2021-09-27 20:06:45",
     * "updateTime":"2021-09-27 20:06:45","status":"0"}
     *
     * @param tbLetter
     * @return
     */
    @PostMapping(value = "/add", consumes = "application/json")
    public HashMap<String, Object> add(@RequestBody TbLetter tbLetter) {
        return tbLetterService.add(tbLetter);
    }

    /**
     * 修改
     * http://localhost:8080/tb-letter/update
     * {"id":"1","status":"1"}
     *
     * @param tbLetter
     * @return
     */
    @PutMapping(value = "/update", consumes = "application/json")
    public HashMap<String, Object> update(@RequestBody TbLetter tbLetter) {
        return tbLetterService.update(tbLetter);
    }

    /**
     * 删除
     * http://localhost:8080/tb-letter/del/?
     *
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public HashMap<String, Object> del(@PathVariable Integer id) {
        return tbLetterService.del(id);
    }

    /**
     * 查询
     * http://localhost:8080/tb-letter/list?page=1&row=2
     *
     * @param tbLetter
     * @return
     */
    @GetMapping("/list")
    public HashMap<String, Object> list(TbLetter tbLetter) {
        return tbLetterService.list(tbLetter);
    }

    /**
     * http://localhost:8080/tb-letter/ownerName/xxx
     *
     * @param ownerName
     * @return
     */
    @GetMapping("/ownerName/{ownerName}")
    public HashMap<String, Object> letterFrom(@PathVariable String ownerName) {
        return tbLetterService.letterFrom(ownerName);
    }

    /**
     * http://localhost:8080/tb-letter/email
     *
     * @param email
     * @return
     */
    @GetMapping(value = "/email")
    public HashMap<String, Object> sendEmail(TbLetterEmail email) {
        HashMap<String, Object> map = tbLetterService.sendEmail(email);
        return map;
    }
}

